package com.promise.jokerdream.navigation

import androidx.compose.runtime.*
import androidx.compose.ui.unit.dp

/**
 * 应用导航状态管理
 */
class AppNavigationState {
    private val _currentRoute = mutableStateOf<AppRoute>(AppRoute.Main)
    val currentRoute: State<AppRoute> = _currentRoute
    
    private val _navigationStack = mutableStateOf<List<AppRoute>>(listOf(AppRoute.Main))
    val navigationStack: State<List<AppRoute>> = _navigationStack
    
    fun navigateTo(route: AppRoute) {
        _currentRoute.value = route
        _navigationStack.value = _navigationStack.value + route
    }
    
    fun navigateBack(): Boolean {
        return if (_navigationStack.value.size > 1) {
            _navigationStack.value = _navigationStack.value.dropLast(1)
            _currentRoute.value = _navigationStack.value.last()
            true
        } else {
            false
        }
    }
    
    fun canGoBack(): Boolean = _navigationStack.value.size > 1
}


/**
 * 记住导航状态
 */
@Composable
fun rememberAppNavigationState(): AppNavigationState {
    return remember { AppNavigationState() }
}
